<template>
	<view class="report-box" @touchmove.stop.prevent="moveHandle">
		<view class="report-disalog">
			<view class="disalog-title">
				{{title}}
			</view>
			<view class="disalog-content">
				<view class="input-title">备注</view>
				<textarea class="remark-input" @input="textChange" placeholder-style="color:#9e9e9e" placeholder="输入备注信息" />
				<view class="upload-title">
					上传图片
				</view>
				<view class="img-box">
					<view class="image-item" v-for="(item,index) in imgList" :key="index">
						<image class="priview-img" :src="item"
							mode="aspectFill"></image>
						<image @click="closeImg(index)" class="close-icon" src="/static/image/close_blue_icon.png" mode="aspectFit">
						</image>
					</view>
					<view class="upload-input-box" @click="uploadImg" v-if="imgList.length < 4">
						<image class="icon" src="/static/image/upload_img_icon.png" mode="aspectFit"></image>
						<view class="text">
							上传图片和资料
						</view>
					</view>
				</view>
				<view class="button-box" @click="cancel">
					<view class="button cancel-button">
						取消
					</view>
					<view @click="confirm" class="button confirm-button">
						确定
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			title:{
				type:String,
				default:'提报'
			},
			type:{
				type:String,
				default:''
			}
		},
		data() {
			return {
				imgList:[],
				text:'',
			}
		},
		methods: {
			/**
			 * 输入框输入文本触发事件
			 */
			textChange:function(e){
				this.$emit('inputChange',e.target.value);
			},
			/**
			 * 上传图片/附件点击触发事件
			 */
			uploadImg:function(){
				let that = this;
				let count = 4;
				let imgList = that.imgList;
				if(imgList.length < count){
					uni.chooseImage({
						count: count - imgList.length,
						sizeType: ['original', 'compressed'],
						sourceType: ['album'], //从相册选择
						success: function (res) {
							imgList.push.apply(imgList,res.tempFilePaths);
							that.imgList = imgList;
						}
					});
				}
				
			},
			/**
			 *  删除图片点击触发事件
			 */
			closeImg:function(index){
				let imgList = this.imgList;
				imgList.splice(index, 1);
				this.imgList = imgList;
			},
			/**
			 * 取消按钮点击触发事件
			 */
			cancel:function(){
				this.$emit('cancel');
			},
			/**
			 * 确认按钮点击触发事件
			 */
			confirm:function(){
				let data = {type:this.type,imgList:this.imgList};
				this.$emit('confirm',data);
			},
			moveHandle(){
				return;
			},
		}
	}
</script>

<style lang="scss" scoped>
	.report-box {
		position: fixed;
		width: 100%;
		height: 100vh;
		top: 0;
		left: 0;
		background: rgba(20, 20, 20, 0.5);
	}

	.report-disalog {
		background-color: white;
		border-radius: 10rpx;
		margin: 0 auto;
		position: relative;
		top: 20%;
		animation-name: disalogshow;
		animation-duration: 0.5s;
		width: calc(100% - 180rpx);
		box-sizing: border-box;
		padding: 20rpx;

		.disalog-title {
			text-align: center;
		}

		.disalog-content {
			margin-top: 30rpx;

			.remark-input {
				background-color: #f4f4f4;
				width: 100%;
				box-sizing: border-box;
				height: 200rpx;
				padding: 20rpx;
			}

			.upload-title {
				line-height: 80rpx;
			}
			.img-box{
				display: flex;
				flex-wrap: wrap;
				overflow: hidden;
				.image-item{
					float: left;
					margin-right: 10rpx;
					position: relative;
					.priview-img{
						width: 160rpx;
						height: 140rpx;
						border:2rpx solid #5377c3;
					}
					.close-icon{
						width: 40rpx;
						height: 40rpx;
						position: absolute;
						right: 5rpx;
						top: 5rpx;
					}
				}
			}
			.upload-input-box {
				width: 180rpx;
				padding: 30rpx 0;
				border: 2rpx solid #afafaf;
				border-radius: 10rpx;

				.icon {
					width: 60rpx;
					height: 60rpx;
					display: block;
					margin: 0 auto;
				}

				.text {
					color: #c9c9c9;
					font-size: 20rpx;
					text-align: center;
				}
			}
		}

		.button-box {
			display: flex;
			margin-top: 30rpx;
			justify-content: space-around;

			.button {
				width: calc(50% - 20rpx);
				line-height: 70rpx;
				text-align: center;
				color: white;
				border-radius: 10rpx;
			}

			.cancel-button {
				background-color: #888888;
			}

			.confirm-button {
				background-color: #36af86;
			}
		}
	}

	@keyframes disalogshow {
		0% {
			// transform: scale(0);
			opacity: 0;
		}

		100% {
			// transform: scale(1);
			opacity: 1;
		}
	}
</style>
